package net.wanho.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.PlaceDTO;
import net.wanho.po.Place;
import net.wanho.service.PlaceService;
import net.wanho.mapper.PlaceMapper;
import net.wanho.vo.PageInfo;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【place(产地表)】的数据库操作Service实现
* @createDate 2025-04-28 11:41:58
*/
@Service
public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, Place>
    implements PlaceService{

    @Override
    public PageInfo<Place> pageList(int pageNum, int pageSize, PlaceDTO placeDTO) {
        Page<Place> page = new Page<>(pageNum, pageSize);

        QueryWrapper<Place> wrapper = new QueryWrapper<>();
        wrapper.like(!ObjectUtil.isEmpty(placeDTO.getPlaceName()), "place_name", placeDTO.getPlaceName());
        wrapper.eq(!ObjectUtil.isEmpty(placeDTO.getPlaceNum()), "place_num", placeDTO.getPlaceNum());
        Page<Place> p = this.baseMapper.selectByPage(page, wrapper);

        PageInfo<Place> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getPages());
        pageInfo.setLimitIndex(page.offset());
        pageInfo.setResultList(p.getRecords());

        return pageInfo;
    }

    @Override
    public Boolean selectIdByPlaceName(String placeNum) {
        Place place = this.baseMapper.selectOne(new QueryWrapper<Place>().eq("place_num", placeNum));
        return place == null;
    }
}




